window.alert = alert;

function alert(n) {//n - 题号
    //创建元素
    var f = document.createElement("div"), 
        a = document.createElement("div"),
        p = document.createElement("p"),
        btn3 = document.createElement("div"),
        link1 = document.createElement("a"),
        p2 = document.createElement("p"),
        pText = document.createTextNode("提示"),
        pText2 = document.createTextNode("确认要删除此问卷？"),
        btnText3 = document.createTextNode("x"),
        btn1 = document.createElement("div"),
        btn2 = document.createElement("div"),
        btnText1 = document.createTextNode("确定"),
        btnText2 = document.createTextNode("取消");
    // 控制样式
    css(f, {
        "width" : "100%",
        "height" : "777px",
        "position" : "fixed",
        "top" : "0px",
        "background-image": "url(../img/Background1.png)",
        "z-index" : "1"
    });
    css(a, {
        "position": "fixed",
        "left": "0",
        "right": "0",
        "top": "20%",
        "width": "350px",
        "height": "150px",
        "margin": "0 auto",
        "background-color": "white",
        "font-size": "15px",
        "border-radius": "4px",
        "box-shadow": "rgb(177, 177, 177) 0px 2px 5px",
        "z-index" : "10"
    });
    css(p, {
        "height" : "35px",
        "margin" : "0",
        "background" : "rgb(211, 208, 208)",
        "font-weight" : "600",
        "line-height" : "35px",
        "border-radius": "4px",
        "padding-left" : "20px"
    });
    css(p2, {
        "height" : "35px",
        "line-height" : "35px",
        "padding-left" : "20px"
    });
    css(btn1, {
        "position": "relative",
        "left": "110px",
        "right": "0",
        "top": "23%",
        "width": "50px",
        "height": "23px",
        "color" : "black",
        "border-radius": "2px",
        "border" : "solid gray 1px",
        // "background": "rgb(241, 112, 53)",
        "text-align": "center",
        "display" : "inline-block"
    });
    css(btn2, {
        "position": "relative",
        "left": "140px",
        "right": "0",
        "top": "23%",
        "width": "50px",
        "height": "23px",
        "border" : "solid gray 1px",
        "text-align": "center",
        "display" : "inline-block",
        "border-radius": "2px"
    });
    css(btn3, {
        "width" : "30px",
        "display" : "inline-block",
        "margin-left" : "270px",
        "text-align" : "center"

    });
    // 内部结构套入
    link1.appendChild(btnText1);
    btn2.appendChild(btnText2);
    btn3.appendChild(btnText3);
    link1.setAttribute("href","./list.html");
    btn1.appendChild(link1);
    p.appendChild(pText);
    p.appendChild(btn3);
    p2.appendChild(pText2);
    // btn3.appendChild(link3);
    f.appendChild(a);
    a.appendChild(p);
    a.appendChild(p2);
    a.appendChild(btn1);
    a.appendChild(btn2);
    
    // 整体显示到页面内
    document.getElementsByTagName("body")[0].appendChild(f);

    // 确定绑定点击事件删除标签
    btn1.onclick = function (n) {
        a.parentNode.removeChild(a);
        f.parentNode.removeChild(f);
        deleteBtnOfQuestionnaire(n);
    }
    btn2.onclick = function () {
        a.parentNode.removeChild(a);
        f.parentNode.removeChild(f);
    }
    btn3.onclick = function () {
        a.parentNode.removeChild(a);
        f.parentNode.removeChild(f);
    }
}

function css(targetObj, cssObj) {
    var str = targetObj.getAttribute("style") ? targetObj.getAttribute("style") : "";
    for (var i in cssObj) {
        str += i + ":" + cssObj[i] + ";";
    }
    targetObj.style.cssText = str;
}